/*
 * JaCoLiB
 * Copyright (C) 2008 Alessandro Serra
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */


package it.gashale.jacolib.main.configurator.scripts;

import it.gashale.jacolib.core.JacolibError;
import it.gashale.jacolib.main.Jacolib;
import it.gashale.jacolib.main.configurator.Configurator;
import it.gashale.jacolib.shell.RemoteShell;


public class RemoteShellConfigurator extends Configurator {
	
	public void configure(Jacolib jacolib) throws JacolibError  {
		RemoteShell rs=makePeerProxy(jacolib);
		configure(rs);
	}
	public RemoteShell makePeerProxy(Jacolib jacolib) throws JacolibError {
		RemoteShell rs=null;
		String name=getValue(new String[]{"Name"}, null);
		String host=getValue(new String[]{"Host"}, null);
		String port_str=getValue(new String[]{"Port"}, null);
		int port=Integer.parseInt(port_str);
		String password=getValue(new String[]{"Password"},null);
		rs=jacolib.connect(name,host, port, password);
		return rs;
	}
	public void configure(RemoteShell shell) throws JacolibError {
		String init_file=getValue(new String[]{"Init","Source"}, "");
		if(init_file!=null && !init_file.equals("")) {
			shell.source(init_file);
		}
		String init_eval=getValue(new String[]{"Init","Eval"}, "");
		if(init_eval!=null && !init_eval.equals("")) {
			shell.eval(init_eval);
		}
	}
	
}
